package org.example.device.protocol;

import java.util.Map;

/**
 * 协议通信结果
 */
public class ProtocolResult {
    
    private boolean success;
    private String message;
    private Object data;
    private String errorCode;
    private Map<String, Object> metadata;
    private Long timestamp;
    
    public ProtocolResult() {
        this.timestamp = System.currentTimeMillis();
    }
    
    public ProtocolResult(boolean success, String message) {
        this.success = success;
        this.message = message;
        this.timestamp = System.currentTimeMillis();
    }
    
    public static ProtocolResult success(String message) {
        return new ProtocolResult(true, message);
    }
    
    public static ProtocolResult success(String message, Object data) {
        ProtocolResult result = new ProtocolResult(true, message);
        result.setData(data);
        return result;
    }
    
    public static ProtocolResult failure(String message) {
        return new ProtocolResult(false, message);
    }
    
    public static ProtocolResult failure(String message, String errorCode) {
        ProtocolResult result = new ProtocolResult(false, message);
        result.setErrorCode(errorCode);
        return result;
    }
    
    // Getter和Setter方法
    public boolean isSuccess() {
        return success;
    }
    
    public void setSuccess(boolean success) {
        this.success = success;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public Object getData() {
        return data;
    }
    
    public void setData(Object data) {
        this.data = data;
    }
    
    public String getErrorCode() {
        return errorCode;
    }
    
    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
    
    public Map<String, Object> getMetadata() {
        return metadata;
    }
    
    public void setMetadata(Map<String, Object> metadata) {
        this.metadata = metadata;
    }
    
    public Long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }
}
